<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
             targetNamespace="Examples">

  <process id="process" isExecutable="true">

    <startEvent id="theStart">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </startEvent>

    <sequenceFlow sourceRef="theStart" targetRef="theService1" />

    <serviceTask id="theService1" camunda:expression="${true}">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </serviceTask>

    <sequenceFlow sourceRef="theService1" targetRef="join" />

    <exclusiveGateway id="join">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </exclusiveGateway>

    <sequenceFlow sourceRef="join" targetRef="theScript" />

    <scriptTask id="theScript" scriptFormat="groovy">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
      <script>
        <![CDATA[
          def counterVar = execution.getVariable("counter")
          def int counter = 0
          if (counterVar != null) {
            counter = counterVar
          }
          counter = counter + 1
          execution.setVariable("counter", counter)
        ]]>
      </script>
    </scriptTask>

    <sequenceFlow sourceRef="theScript" targetRef="fork" />

    <exclusiveGateway id="fork">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </exclusiveGateway>

    <sequenceFlow sourceRef="fork" targetRef="join">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${counter < 2}]]></conditionExpression>
    </sequenceFlow>

    <sequenceFlow sourceRef="fork" targetRef="theService2" >
      <conditionExpression xsi:type="tFormalExpression">${counter >= 2}</conditionExpression>
    </sequenceFlow>

    <serviceTask id="theService2" camunda:expression="${true}">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </serviceTask>

    <sequenceFlow sourceRef="theService2" targetRef="theEnd" />

    <endEvent id="theEnd">
      <extensionElements>
        <camunda:executionListener event="start" class="org.camunda.bpm.engine.test.standalone.entity.ExecutionOrderListener" />
      </extensionElements>
    </endEvent>

  </process>

</definitions>